<template>
  <div class="app-container">

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="success"  size="mini"  @click="handleYes" v-hasPermi="['system:user:remove']">同意</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" size="mini" @click="handleNo" v-hasPermi="['system:user:remove']">打回</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['gzys:gzys:export']"
        >导出
        </el-button>
      </el-col>
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    </el-row>

  <!--主子表-->
    <el-table
      v-loading="loading"
      :data="gzysList"
      @selection-change="handleSelectionChange"
      style="width: 100%"
      @expand-change="getSubTableData"
    >
      <el-table-column type="expand">
        <template slot-scope="" #default="scope">
          <h4>购置预算明细</h4>
          <el-table :data="scope.row.childData" v-loading="loading">

            <el-table-column label="填报单位" prop="dcode" />
            <el-table-column label="资产分类" prop="codee" />
            <el-table-column label="资产名称" prop="zcname" />
            <el-table-column label="单位" prop="per" />
            <el-table-column label="数量" prop="num" />
            <el-table-column label="单价" prop="price" />
            <el-table-column label="总价" prop="numprice" />
            <el-table-column label="购置数量" prop="gzsum" />
            <el-table-column label="购置总价" prop="gzprice" />
          </el-table>
        </template>
      </el-table-column>
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="标题" align="center" prop="title" />
      <el-table-column label="填报日期" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="单位名称" align="center" prop="dname" />
      <el-table-column label="预算数量" align="center" prop="sumnum" />
      <el-table-column label="预算总价" align="center" prop="sumprice" />
      <el-table-column label="已购数量" align="center" prop="num" />
      <el-table-column label="已购总价" align="center" prop="summoney" />
      <el-table-column label="流程状态" align="center" prop="status" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="success"
            style="width: 50px"
            @click="handleYes(scope.row)"
            v-hasPermi="['approveys:approveys:yes']"
          >同意</el-button>
          <el-button
            size="mini"
            type="warning"
            style="width: 50px"
            @click="handleNo(scope.row)"
            v-hasPermi="['approveys:approveys:No']"
          >打回</el-button>
        </template>
      </el-table-column>
    </el-table>
  <!--主子表结束-->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listGzys, getGzys, delGzys, addGzys, updateGzys} from "@/api/gzys/gzys";
import {listGzysMx} from "@/api/gzys/zi"
import { delAssestSort } from '@/api/assestSort/assestSort'
import { handleNo, handleYes } from '@/api/approveys/approveys'

export default {
  name: "Gzys",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedAssetGzyusuanZi: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 购置预算表格数据
      gzysList: [],
      //*******************购置预算明细表格数据***************
      ziList:[],
      childData:[],
      // 购置预算明细表格数据
      assetGzyusuanZiList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open1:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sid: null,
        title: null,
        startTime: null,
        dname: null,
        sumnum: null,
        sumprice: null,
        num: null,
        summoney: null,
        status: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询购置预算列表 */
    getList() {
      this.loading = true;
      listGzys(this.queryParams).then(response => {
        this.gzysList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //*************************
    /**查询购置明细*/
    getSubTableData(row){
      this.loading = true;
      listGzysMx(row.id).then(response => {
        row.childData = response.rows;
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.open1 = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sid: null,
        title: null,
        startTime: null,
        dname: null,
        sumnum: null,
        sumprice: null,
        num: null,
        summoney: null,
        status: null
      };
      this.assetGzyusuanZiList = [];
      this.resetForm("form");
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    handleYes(row) {
      const companyIds = row.id || this.ids;
      this.$modal.confirm('是否确认同意公司的预算审批？').then(function() {
        return handleYes(companyIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("审批成功");
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消审批'
        });
      });
    },

    handleNo(row) {
      const companyIds = row.id || this.ids;
      this.$modal.confirm('是否确认打回公司的预算审批？').then(function() {
        return handleNo(companyIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("成功打回");
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消审批'
        });
      });


    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('gzys/gzys/export', {
        ...this.queryParams
      }, `gzys_${new Date().getTime()}.xlsx`)
    }
  }
};

</script>
<style>
h4{
  color:green;
}
</style>
